<?php

/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */

/**
 * @see Zend_Gdata_Extension
 */
require_once 'Zend/Gdata/Extension.php';

/**
 * Data model class to represent Portfolio Data
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @copyright  Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Gdata_Finance_Extension_PortfolioData extends Zend_Gdata_Extension
{
	protected $_rootNamespace = 'gf';
	protected $_rootElement = 'portfolioData';
	/**
	 * The ISO currency code
	 *
	 * @var String
	 */
	protected $_currencyCode = null;
	/**
	 * @var String
	 */
	protected $_gainPercentage = null;
	/**
	 * @var String
	 */
	protected $_return1w = null;
	/**
	 * @var String
	 */
	protected $_return4w = null;
	/**
	 * @var String
	 */
	protected $_return3m = null;
	/**
	 * @var String
	 */
	protected $_returnYTD = null;
	/**
	 * @var String
	 */
	protected $_return1y = null;
	/**
	 * @var String
	 */
	protected $_return3y = null;
	/**
	 * @var String
	 */
	protected $_return5y = null;
	/**
	 * @var String
	 */
	protected $_returnOverall = null;
	/**
	 * @var Zend_Gdata_Finance_Extension_CostBasis
	 */
	protected $_costBasis  = null;
	/**
	 * @var Zend_Gdata_Finance_Extension_DaysGain
	 */
	protected $_daysGain = null;
	/**
	 * @var Zend_Gdata_Finance_Extension_Gain
	 */
	protected $_gain = null;
	/**
	 * @var Zend_Gdata_Finance_Extension_MarketValue
	 */
	protected $_marketValue = null;

	/**
	 * Constructs a new Zend_Gdata_Finance_Extension_PortfolioData object.
	 *
	 * @param string $currencyCode (optional) ISO4217 currency code.
	 */
	public function __construct($currencyCode = null)
	{
		foreach (Zend_Gdata_Finance::$namespaces as $nsPrefix => $nsUri) {
			$this->registerNamespace($nsPrefix, $nsUri);
		}
		parent::__construct();
		$this->_currencyCode = $currencyCode;
	}

	/**
	 * Retrieves a DOMElement which corresponds to this element and all
	 * child properties.  This is used to build an entry back into a DOM
	 * and eventually XML text for sending to the server upon updates, or
	 * for application storage/persistence.
	 *
	 * @param DOMDocument $doc The DOMDocument used to construct DOMElements
	 * @return DOMElement The DOMElement representing this element and all
	 * child properties.
	 */
	public function getDOM($doc = null)
	{
		$element = parent::getDOM($doc);
		if ($this->_currencyCode != null)
		{
			$element->setAttribute('currencyCode', $this->_currencyCode);
		}
		if ($this->_gainPercentage != null)
		{
			$element->setAttribute('gainPercentage', $this->_gainPercentage);
		}
		if ($this->_return1w != null)
		{
			$element->setAttribute('return1w', $this->_return1w);
		}
		if ($this->_return4w != null)
		{
			$element->setAttribute('return4w', $this->_return4w);
		}
		if ($this->_return3m != null)
		{
			$element->setAttribute('return3m', $this->_return3m);
		}
		if ($this->_returnYTD != null)
		{
			$element->setAttribute('returnYTD', $this->_returnYTD);
		}
		if ($this->_return3y != null)
		{
			$element->setAttribute('return3y', $this->_return3y);
		}
		if ($this->_return5y != null)
		{
			$element->setAttribute('retur5y', $this->return5y);
		}
		if ($this->_returnOverall != null)
		{
			$element->setAttribute('returnOverall', $this->returnOverall);
		}
		if ($this->_costBasis != null)
		{
			$element->appendChild($this->_costBasis->getDOM($element->ownerDocument));
		}
		if ($this->_daysGain != null)
		{
			$element->appendChild($this->_daysGain->getDOM($element->ownerDocument));
		}
		if ($this->_gain != null)
		{
			$element->appendChild($this->_gain->getDOM($element->ownerDocument));
		}
		if ($this->_marketValue != null)
		{
			$element->appendChild($this->_marketValue->getDOM($element->ownerDocument));
		}

		return $element;
	}

	/**
	 * Given a DOMNode representing an attribute, tries to map the data into
	 * instance members.  If no mapping is defined, the name and value are
	 * stored in an array.
	 *
	 * @param DOMNode $attribute The DOMNode attribute needed to be handled
	 */
	protected function takeAttributeFromDOM($attribute)
	{
		switch ($attribute->localName) {
			case 'currencyCode':
				$this->_currencyCode = $attribute->nodeValue;
				break;
			case 'gainPercentage':
				$this->_gainPercentage = $attribute->nodeValue;
				break;
			case 'return1w':
				$this->_return1w = $attribute->nodeValue;
				break;
			case 'return4w':
				$this->_return4w = $attribute->nodeValue;
				break;
			case 'return3m':
				$this->_return3m = $attribute->nodeValue;
				break;
			case 'returnYTD':
				$this->_returnYTD = $attribute->nodeValue;
				break;
			case 'return1y':
				$this->_return1y = $attribute->nodeValue;
				break;
			case 'return3y':
				$this->_return3y = $attribute->nodeValue;
				break;
			case 'return5y':
				$this->_return5y = $attribute->nodeValue;
				break;
			case 'returnOverall':
				$this->_returnOverall = $attribute->nodeValue;
				break;
			default:
				parent::takeAttributeFromDOM($attribute);
		}
	}


	/**
	 * Creates individual Entry objects of the appropriate type and
	 * stores them as members of this entry based upon DOM data.
	 *
	 * @param DOMNode $child The DOMNode to process
	 */
	protected function takeChildFromDOM($child)
	{
		$absoluteNodeName = $child->namespaceURI . ':' . $child->localName;

		switch ($absoluteNodeName) {
			case $this->lookupNamespace('gf') . ':' . 'costBasis':
				$obj = new Zend_Gdata_Finance_Extension_CostBasis();
				$obj->transferFromDOM($child);
				$this->_costBasis = $obj;
				break;
			case $this->lookupNamespace('gf') . ':' . 'daysGain':
				$obj =	 new Zend_Gdata_Finance_Extension_daysGain();
				$obj->transferFromDOM($child);
				$this->_daysGain = $obj;
				break;
			case $this->lookupNamespace('gf') . ':' . 'gain':
				$obj =	 new Zend_Gdata_Finance_Extension_Gain();
				$obj->transferFromDOM($child);
				$this->_gain = $obj;
				break;
			case $this->lookupNamespace('gf') . ':' . 'marketValue':
				$obj = new Zend_Gdata_Finance_Extension_MarketValue();
				$obj->transferFromDOM($child);
				$this->_marketValue = $obj;
				break;
			default:
				parent::takeChildFromDOM($child);
				break;
		}
	}

	/**
	 * Get the value for this elements currencyCode  attribute.
	 *
	 * @return string $currencyCode The requested attribute.
	 */
	public function getCurrencyCode()
	{
		return $this->_currencyCode;
	}

	/**
	 * Set the value for this elements currencyCode attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setCurrencyCode($value)
	{
		$this->_currencyCode = $value;
		return $this;
	}

	/**
	 * Get the value for this elements gainPercentage  attribute.
	 *
	 * @return string $gainPercentage The requested attribute.
	 */
	public function getGainPercentage()
	{
		return $this->_gainPercentage;
	}

	/**
	 * Set the value for this elements gainPercentage attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setGainPercentage($value)
	{
		$this->_gainPercentage = $value;
		return $this;
	}

	/**
	 * Get the value for this elements return1w  attribute.
	 *
	 * @return string $return1w The requested attribute.
	 */
	public function getReturn1w()
	{
		return $this->_return1w;
	}

	/**
	 * Set the value for this elements return1w attribute.
	 *
	 * @param string $value  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturn1w($value)
	{
		$this->_return1w = $value;
		return $this;
	}

	/**
	 * Get the value for this elements return4w  attribute.
	 *
	 * @return string $return4w The requested attribute.
	 */
	public function getReturn4w()
	{
		return $this->_return4w;
	}

	/**
	 * Set the value for this elements return4w attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturn4w($value)
	{
		$this->_return4w = $value;
		return $this;
	}

	/**
	 * Get the value for this elements return3m  attribute.
	 *
	 * @return string $return3m The requested attribute.
	 */
	public function getReturn3m()
	{
		return $this->_return3m;
	}

	/**
	 * Set the value for this elements return3m attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturn3m($value)
	{
		$this->_return3m = $value;
		return $this;
	}

	/**
	 * Get the value for this elements returnYTD  attribute.
	 *
	 * @return string $returnYTD The requested attribute.
	 */
	public function getReturnYTD()
	{
		return $this->_returnYTD;
	}

	/**
	 * Set the value for this elements returnYTD attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturnYTD($value)
	{
		$this->_returnYTD = $value;
		return $this;
	}

	/**
	 * Get the value for this elements return1y  attribute.
	 *
	 * @return string $return1y The requested attribute.
	 */
	public function getReturn1y()
	{
		return $this->_return1y;
	}

	/**
	 * Set the value for this elements return1y attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturn1y($value)
	{
		$this->_return1y = $value;
		return $this;
	}

	/**
	 * Get the value for this elements return3y  attribute.
	 *
	 * @return string $return3y The requested attribute.
	 */
	public function getReturn3y()
	{
		return $this->_return3y;
	}

	/**
	 * Set the value for this elements return3y attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturn3y($value)
	{
		$this->_return3y = $value;
		return $this;
	}

	/**
	 * Get the value for this elements return5y  attribute.
	 *
	 * @return string $return5y The requested attribute.
	 */
	public function getReturn5y()
	{
		return $this->_return5y;
	}

	/**
	 * Set the value for this elements return5y attribute.
	 *
	 * @param string $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturn5y($value)
	{
		$this->_return5y = $value;
		return $this;
	}

	/**
	 * Get the value for this elements returnOverall  attribute.
	 *
	 * @return string $returnOverall The requested attribute.
	 */
	public function getReturnOverall()
	{
		return $this->_returnOverall;
	}

	/**
	 * Set the value for this elements returnOverall attribute.
	 *
	 * @param string  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setReturnOverall($value)
	{
		$this->_returnOverall = $value;
		return $this;
	}

	/**
	 * Get the value for this elements costBasis  attribute.
	 *
	 * @return Zend_Gdata_Finance_Extension_CostBasis $costBasis The requested attribute.
	 */
	public function getCostBasis()
	{
		return $this->_costBasis;
	}

	/**
	 * Set the value for this elements costBasis attribute.
	 *
	 * @param Zend_Gdata_Finance_Extension_CostBasis $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setCostBasis(Zend_Gdata_Finance_Extension_CostBasis $value)
	{
		$this->_costBasis = $value;
		return $this;
	}

	/**
	 * Get the value for this elements daysGain  attribute.
	 *
	 * @return Zend_Gdata_Finance_Extension_DaysGain $daysGain The requested attribute.
	 */
	public function getDaysGain()
	{
		return $this->_daysGain;
	}

	/**
	 * Set the value for this elements daysGain attribute.
	 *
	 * @param Zend_Gdata_Finance_Extension_DaysGain $value The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setDaysGain(Zend_Gdata_Finance_Extension_DaysGain $value)
	{
		$this->_daysGain = $value;
		return $this;
	}

	/**
	 * Get the value for this elements gain  attribute.
	 *
	 * @return Zend_Gdata_Finance_Extension_Gain $gain The requested attribute.
	 */
	public function getGain()
	{
		return $this->_gain;
	}

	/**
	 * Set the value for this elements gain attribute.
	 *
	 * @param Zend_Gdata_Finance_Extension_Gain $value  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setGain(Zend_Gdata_Finance_Extension_Gain $value)
	{
		$this->_gain = $value;
		return $this;
	}

	/**
	 * Get the value for this elements marketValue  attribute.
	 *
	 * @return Zend_Gdata_Finance_Extension_MarketValue $marketValue The requested attribute.
	 */
	public function getMarketValue()
	{
		return $this->_marketValue;
	}

	/**
	 * Set the value for this elements marketValue attribute.
	 *
	 * @param Zend_Gdata_Finance_Extension_MarketValue $value  The desired value for this attribute.
	 * @return Zend_Gdata_Finance_Extension_PortfolioData The element being modified.
	 */
	public function setMarketValue(Zend_Gdata_Finance_Extension_MarketValue $value)
	{
		$this->_marketValue = $value;
		return $this;
	}
}